package com.touzhijia.scheduler.vo.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.touzhijia.common.vo.request.BaseRequestVo;
import com.touzhijia.scheduler.vo.model.HttpJobData;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 新增一个HttpJob
 * <p>
 * 作者：lizw <br/>
 * 创建时间：2017/6/5 13:55 <br/>
 */
public class AddHttpServiceJobVo extends BaseRequestVo {
    private static final long serialVersionUID = 1L;

    //--------------------------------------------------------------------------------------------------------------------------------------
    //     Job配置
    // -------------------------------------------------------------------------------------------------------------------------------------

    /**
     * Job、Trigger 名称
     */
    @NotBlank(message = "JobName不能为空")
    @Length(max = 200, message = "JobName长度不能超过200")
    private String name;

    /**
     * Job、Trigger group名称
     */
    @NotBlank(message = "JobGroup不能为空")
    @Length(max = 200, message = "JobGroup长度不能超过200")
    private String group;

    /**
     * Job描述， .withDescription()方法传入的string
     */
    @Length(max = 250, message = "Job描述长度不能超过250")
    private String description;

    /**
     * Scheduler实例发生故障时，故障恢复节点会检测故障的Scheduler正在调度的任务是否需要recovery(复苏)，如果需要会添加一个只执行一次的simple trigger重新触发
     */
    private boolean requestsRecovery = true;

    //--------------------------------------------------------------------------------------------------------------------------------------
    //     触发器配置
    // -------------------------------------------------------------------------------------------------------------------------------------

    /**
     * 开始触发时间
     */
    @NotNull(message = "开始触发时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    private Date startTime;

    /**
     * 结束触发时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    private Date endTime;

    /**
     * 优先级
     */
    @Range(min = 1, max = 10, message = "Trigger优先级取值范围:1~10")
    private Integer priority;

    /**
     * cron表达式
     */
    @NotBlank(message = "触发的时间间隔不能为空")
    private String cron;

    /**
     * Quartz的Misfire处理规则取值
     */
    private Integer misfireInstruction;

    //--------------------------------------------------------------------------------------------------------------------------------------
    //     Http请求配置
    // -------------------------------------------------------------------------------------------------------------------------------------

    @Valid
    @NotNull(message = "Http请求配置不能为空")
    private HttpJobData httpJobData;

    /*--------------------------------------------------------------
     *          getter、setter
     * -------------------------------------------------------------*/

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean isRequestsRecovery() {
        return requestsRecovery;
    }

    public void setRequestsRecovery(boolean requestsRecovery) {
        this.requestsRecovery = requestsRecovery;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public String getCron() {
        return cron;
    }

    public void setCron(String cron) {
        this.cron = cron;
    }

    public Integer getMisfireInstruction() {
        return misfireInstruction;
    }

    public void setMisfireInstruction(Integer misfireInstruction) {
        this.misfireInstruction = misfireInstruction;
    }

    public HttpJobData getHttpJobData() {
        return httpJobData;
    }

    public void setHttpJobData(HttpJobData httpJobData) {
        this.httpJobData = httpJobData;
    }
}
